package com.ruoyi.web.controller.map;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MapMarksRanking;
import com.ruoyi.system.domain.vo.MapMarksRankingVo;
import com.ruoyi.system.service.IMapMarksRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业排名Controller
 *
 * @author cqust_icc
 * @date 2022-07-15
 */
@RestController
@RequestMapping("/system/ranking")
public class MapMarksRankingController extends BaseController {
    @Autowired
    private IMapMarksRankingService mapMarksRankingService;

    /**
     * 查询企业排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:list')")
    @GetMapping("/list")
    public TableDataInfo list(MapMarksRanking mapMarksRanking) {
        startPage();
        List<MapMarksRanking> list = mapMarksRankingService.selectMapMarksRankingList(mapMarksRanking);
        return getDataTable(list);
    }

    @GetMapping("/select")
    public List<MapMarksRankingVo> select(MapMarksRanking mapMarksRanking) {
        return mapMarksRankingService.selectMapMarksRankingListByCity(mapMarksRanking);
    }

    /**
     * 导出企业排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:export')")
    @Log(title = "企业排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MapMarksRanking mapMarksRanking) {
        List<MapMarksRanking> list = mapMarksRankingService.selectMapMarksRankingList(mapMarksRanking);
        ExcelUtil<MapMarksRanking> util = new ExcelUtil<MapMarksRanking>(MapMarksRanking.class);
        util.exportExcel(response, list, "企业排名数据");
    }

    /**
     * 获取企业排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mapMarksRankingService.selectMapMarksRankingById(id));
    }

    /**
     * 新增企业排名
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:add')")
    @Log(title = "企业排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MapMarksRanking mapMarksRanking) {
        return toAjax(mapMarksRankingService.insertMapMarksRanking(mapMarksRanking));
    }

    /**
     * 修改企业排名
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:edit')")
    @Log(title = "企业排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MapMarksRanking mapMarksRanking) {
        return toAjax(mapMarksRankingService.updateMapMarksRanking(mapMarksRanking));
    }

    /**
     * 删除企业排名
     */
    @PreAuthorize("@ss.hasPermi('system:ranking:remove')")
    @Log(title = "企业排名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mapMarksRankingService.deleteMapMarksRankingByIds(ids));
    }

    @Log(title = "企业排名批量导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:ranking:add')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<MapMarksRanking> util = new ExcelUtil<>(MapMarksRanking.class);
        List<MapMarksRanking> baseList = util.importExcel(file.getInputStream(), 0);
        String message = mapMarksRankingService.importData(baseList);
        return AjaxResult.success(message);
    }
}
